package screenpac.model;

import java.util.ArrayList;
import java.awt.*;

public class Node implements Comparable{
    // nodes carry pill and power pill indices which default to -1
    // meaning that there is neither a pill nor a power pill at this
    // current

    // the index is used to access a BitSet that contains the
    // state of the pills and power pills

    // in this way the game state can be cleanly separated from the
    // maze layout

    public int x,y;
    public int nodeIndex;

    public int pillIndex;
    public int powerIndex;
    public ArrayList<Node> adj;

    public Node(int x, int y) {
        this.x = x;
        this.y = y;
        adj = new ArrayList<Node>();
        pillIndex = -1;
        powerIndex = -1;
    }

    public String toString() {
        return x + " \t " + y;
    }

    // colour should not really be defined here
    // it was a hack to enable display of various
    // node properties
    public Color col = Color.black;
    
    
    /*********************************************************
     * Luis Cruz Mod for GameAI
     * A* Node code
     ********************************************************/
    public float costG;
    public float costH;
    public Node parentNode = null;;
    
    public float getFCost() {
    	return (costG + costH);
    }
    
    public int compareTo(Object other) {
    	float otherValue = ((Node)other).getFCost();
    	float thisValue = this.getFCost();
    	
    	float value = thisValue - otherValue;
    	if(value > 0) return 1;
    	else if(value < 0) return -1;
    	else return 0;
    }
    
    public float getCost(Node node, GameStateInterface gs) {
    	//Check if it has Pill
    	if(gs.getPills().get(node.nodeIndex)) {
    		return 10.0f;
    	}
    	//Check if it has Power pill
    	if(gs.getPowers().get(node.nodeIndex)) {
    		return 2.0f;
    	}
    	//Empty
    	return 14.0f;
    }
    
    public float getHCost(Node node) {
    	// Returns Manhattan Distance
        return Math.abs(node.x - this.x) + Math.abs(node.y - this.y);
    }
}
